cc.Class({
    extends: require('UI-PanelWindow'),

    properties: {
        role0Txt: cc.Label,
        role0Kuang: cc.Node,
        role1Txt: cc.Label,
        role1Kuang: cc.Node,
        plotCfg: cc.JsonAsset,
        _step: 0,
        _content: null,
        farms:[cc.SpriteFrame],
        // head:cc.Sprite,
        text:require('Typewriter')
    },

    start() {
    },

    setOptions(data) {
        this.o_data = data;
        this.n_isEnd = false;
        this._renderContent();
    },

    _renderContent() {
        this._step = 0;
        this._content = this.plotCfg.json[global.gates][this.o_data.status];
        this.clickNext();
    },

    clickNext() {
        this._next();
    },

    _next() {
        if (this._step < this._content.length) {
            this.updateUI();
        } else if (this._step == this._content.length) {
            if (!this.n_isEnd) {
                this.n_isEnd = true;
                this._end();
            }
        }
    },

    updateUI() {
        // this.role0Kuang.active = false;
        // this.role1Kuang.active = false;
        // this.role0Txt.node.active = false;
        // this.role1Txt.node.active = false;
        this.text.next();
        let stepContent = this._content[this._step];
        
        cc.find('view/headImg',this.node).getComponent(cc.Sprite).spriteFrame=this.farms[parseInt(stepContent.role)];
        this.text.setText(stepContent.content);
       /* this['role' + stepContent.role + 'Txt'].string = stepContent.content;
        cc.log(this['role' + stepContent.role + 'Txt'].string);
        this['role' + stepContent.role + 'Kuang'].active = true;
        this['role' + stepContent.role + 'Txt'].node.active = true;*/

        this._step++;
    },

    _end() {
        this.o_data.cb && this.o_data.cb();
        global.UIMgr.popUI();
    },
});
